package com.hypo.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hypo.mapper.StudentMapper;
import com.hypo.pojo.PageResult;
import com.hypo.pojo.Student;
import com.hypo.pojo.StudentQueryParam;
import com.hypo.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;

    /**
     * 查询
     */
    @Override
    public PageResult page(StudentQueryParam studentQueryParam) {
        PageHelper.startPage(studentQueryParam.getPage(), studentQueryParam.getPageSize());
        List<Student> list = studentMapper.list(studentQueryParam);
        Page<Student> pageList = (Page<Student>) list;
        return new PageResult(pageList.getTotal(), list);
    }

    /**
     * 新增
     */
    @Override
    public void add(Student student) {
        student.setCreateTime(LocalDateTime.now());
        student.setUpdateTime(LocalDateTime.now());
        studentMapper.add(student);
    }

    /**
     * 删除
     */
    @Override
    public void del(List<Integer> ids) {
        studentMapper.del(ids);
    }

    /**
     * id回显
     */
    @Override
    public Student getById(Integer id) {
        return studentMapper.getById(id);
    }

    /**
     * 修改
     */
    @Override
    public void modify(Student student) {
        student.setUpdateTime(LocalDateTime.now());
        studentMapper.modify(student);
    }

    @Override
    public void handleScore(Integer id, Integer score) {
        studentMapper.handleScore(id,score);
    }
}
